﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;

namespace CH_k
{
    [Serializable]
    public class LED : Element
    {
        public Color bColor;
        public Color Цвет
        {
            get { return bColor; }
            set { bColor = value; }
        }

        public LED()
        {
            size = new Point(20, 20);
            bColor = Color.LightGreen;
            inElList.Add(null);
            ElType = "LED";
        }

        public override bool Run()
        {
            if (inElList[0] != null)
            {
                return inElList[0].Run();
            }
            return false;
        }
        public override void TryClickInput(Point TCord)
        {
            if (TCord.X == dec.X && TCord.Y == dec.Y + 10)
            {
                        if (inElList[0] == null)
                        {
                            Element.newElement.TrySetOutput(TCord, 0, this);
                        }
            }
        }
        public override void ELineUpdate()
        {
            if (inElList[0] != null)
            {
                inElList[0].output_p = new Point(dec.X, dec.Y + 10);
                inElList[0].pCalc();
            }
        }
        public override void Delete()
        {
            if (inElList[0] != null)
            {
                Element tRef = inElList[0];
                inElList[0].Delete();
                seList.Remove(tRef);
                inElList[0] = null;
            }
        }
        public override void Draw(Graphics _g)
        {
            if (cPen == null) cPen = new Pen(Color.Black);
            Brush b;
            if (Run()) b = new SolidBrush(bColor);
            else b = Brushes.Gray;
            _g.DrawLine(cPen, new Point(dec.X, dec.Y + 10), new Point(dec.X + 10, dec.Y + 10));
            _g.FillEllipse(b, new Rectangle(dec.X + 10, dec.Y, 20, 20));
            _g.DrawEllipse(cPen, new Rectangle(dec.X + 10, dec.Y, 20, 20));
        }
    }
}
